package com.cci.kangdao.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.mybatis.spring.annotation.MapperScan;

import com.cci.kangdao.dao.model.UserT;

@MapperScan
public interface OrderManageDao {

	@Update("update WorkOrder_T set OrderStatus = #{OrderStatus}, ComplainWorkOrderType = #{ComplaintOrderType},RepairerType = #{RepairerType},FaultReason = #{FaultReason}, UpdateTime = #{CurrentTime}, Updator = #{UpdatorId}, ResolveRemoteId = #{ID} where ID = #{OrderId} and UpdateTime = #{UpdateTime}")
	public int updateOrderStatus4ResolveRemote(Map<String, Object> map);
	
	@Insert("INSERT INTO ResolveRemote_T (OrderId ,IsCharged ,ResolveReason ,ChargeDescription ,Remark ,Creator ,CreateTime)\r\n" + 
			"     VALUES ( #{OrderId},#{IsCharged} ,#{ResolveReason} ,#{ChargeDescription} ,#{Remark} ,#{Creator} ,#{CreateTime})")
	@Options(useGeneratedKeys = true, keyProperty = "ID")
	public int insertResolveRemoteRecord(Map<String, Object> map);
	
	@Select("select distinct  a.* from User_T a left join UserHasRoles_T uhr on a.ID = uhr.UserID and uhr.Flag = 0\r\n" +
			"left join UserGroupHasRole_T ughr on uhr.RolesID = ughr.ID and ughr.Flag = 0 \r\n" + 
			"left join Roles_T r on ughr.RoleId = r.ID where a.Flag = 0 and r.Flag = 0 and r.RolesNo = 'R0087'")
	public List<UserT> getManagerList();
	
	@Update("update WorkOrder_T set OrderStatus = #{OrderStatus}, ComplainWorkOrderType = #{ComplaintOrderType},RepairerType = #{RepairerType},FaultReason = #{FaultReason}, UpdateTime = #{CurrentTime}, Updator = #{UpdatorId} where ID = #{OrderId} and UpdateTime = #{UpdateTime}")
	public int updateOrderStatus4AuditFailed(Map<String, Object> map);
	
	@Update("update WorkOrder_T set OrderStatus = #{OrderStatus}, UpdateTime = #{CurrentTime},  Updator = #{UpdatorId} where ID = #{OrderId} and UpdateTime = #{UpdateTime}")
	public int updateOrderStatus4Manager(Map<String, Object> map);

	@Update("update WorkOrder_T set OrderStatus = #{OrderStatus}, UpdateTime = #{CurrentTime}, ConfirmModifyTime = #{ConfirmModifyTime}, Updator = #{UpdatorId} where ID = #{OrderId} and UpdateTime = #{UpdateTime}")
	public int updateOrderStatus4ManagerCcec(Map<String, Object> map);
	
	@Update("update WorkOrder_T set OrderStatus = #{OrderStatus}, ServiceStationId = #{StationId}, GuessDistance = #{Distance}, ComplainWorkOrderType = #{ComplaintOrderType},RepairerType = #{RepairerType},FaultReason = #{FaultReason}, UpdateTime = #{CurrentTime}, Updator = #{UpdatorId} where ID = #{OrderId} and UpdateTime = #{UpdateTime}")
	public int updateOrderStatus4assignSS(Map<String, Object> map);
	
	@Update("update WorkOrder_T set OrderStatus = #{OrderStatus}, ComplainWorkOrderType = #{ComplaintOrderType},RepairerType = #{RepairerType},FaultReason = #{FaultReason}, UpdateTime = #{CurrentTime}, Updator = #{UpdatorId} where ID = #{OrderId} and UpdateTime = #{UpdateTime}")
	public int updateOrderStatus4reassignSS(Map<String, Object> map);
	
	@Update("update WorkOrderPrincipal_T set Flag = -1 where OrderId = #{orderId} and OrderStatus = #{orderStatus} ")
	public void updatePrincipalStatus(@Param("orderId")Long orderId, @Param("orderStatus")int orderStatus);
	
	@Update("update WorkOrder_T set CCSSOrderNo = #{CCSSOrderNo} where ID = #{orderId}")
	public int updateCCSSOrderNo(@Param("CCSSOrderNo") String CCSSOrderNo, @Param("orderId") Long orderId);
	
	@Update("update WorkOrder_T set RelOrderId = #{relOrderId} where ID = #{orderId}")
	public int updateRelOrderId(@Param("relOrderId") Long relOrderId, @Param("orderId") Long orderId);
}
